// ZUBaseFile.cpp: implementation of the CZUBaseFile class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ZUBaseFile.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CZUBaseFile::CZUBaseFile()
{
	m_bZipFile = true;
	m_bDetectZlibMemoryLeaks = true;
	m_pFile = NULL;
}

CZUBaseFile::~CZUBaseFile()
{
	while(m_list.size())
	{
		delete [](*m_list.begin());
		m_list.pop_front();
	}
}

bool CZUBaseFile::IsClosed()
{
	return  m_pFile == NULL;
}

void* CZUBaseFile::myalloc(void* opaque, UINT items, UINT size)
{
	void* p = new char[size * items];
	if (opaque)
	{
		list<char *> *List = (list<char *> *)opaque;
		List->push_back((char *)p);
	}
	return p;
}

void CZUBaseFile::myfree(void* opaque, void* address)
{
	if (opaque)
	{
		list<char *> * List = (list<char *> *)opaque;
		List->remove((char *)address);
	}
	delete[] address;
}

void CZUBaseFile::ThrowError(int err)
{
	throw err;
}

void CZUBaseFile::CheckForError(int err)
{
	if ((err == Z_OK) || (err == Z_NEED_DICT))
		return;

	ThrowError(err);

}